<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登陆页面</title>
<jsp:include page="../common/common.jsp"></jsp:include>
<style>
	#content{
		margin:100px auto;
		width:540px;
		height:350px;
		overflow: hidden;
	}
	#inner01{
		width:250px;
		height:323px;
		margin:10px auto;
		overflow: hidden;
	}
	#yzmjg{
		width:16px;
		height:16px;
		float: right;
		margin-right:40px;
		margin-top:5px; 
	}
	
	
/* http://localhost:8090/cunjin-dorm/login/login.jsp */
</style>
</head>
<body>
	<div id="content">
	
		<div id="p" class="easyui-panel" title="欢迎登陆"     
	        style="width:540px;height:350px;padding:10px;background:#fafafa;"   
	        data-options="">
	        
	        <div id="inner01">
	        
				  用&nbsp;&nbsp;户&nbsp;&nbsp;名:<input name="phone" class="easyui-textbox" value="123" data-options="iconCls:'icon-man'" style="width:170px;height:20px"> 
				  <br/><br/>
				  
				  密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:<input type="password" name="passwode" class="easyui-textbox" value="123" data-options="iconCls:'icon-lock'" style="width:170px;height:20px"> 
				 <br/><br/>
				  手机号码:<input id="sj" name="sj" placeholder="输入手机号码" value="13926583118" class="easyui-numberbox" data-options="required:true,"  style="width:130px;height:20px"> 
				  <a id="btnyzm" href="#" class="easyui-linkbutton"  style="width:60px;height:20px">发送</a>  
				  
				 <br/><br/>
				  验&nbsp;&nbsp;证&nbsp;&nbsp;码:<input id="yzm" name="yzm" placeholder="输入验证码" class="easyui-numberbox" data-options="max:9999" style="width:130px;height:20px"><div id="yzmjg"></div> 
				 <br/><br/>
				 角&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;色:<select id="cc" class="easyui-combobox" name="role" style="width:170px;height:20px">   
				    <option value="1">学生</option>   
				    <option value="2" selected="selected" >管理员</option>   
				</select>  

					<br/><br/>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a id="lg" href="#" class="easyui-linkbutton" >登&nbsp;&nbsp;陆</a>  
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a id="reg" href="#" class="easyui-linkbutton" >去注册</a>  
	        </div>
	                
	
	</div>

</div>  

	

</body>
<script type="text/javascript">

	var loginflag=0;

	$(function(){
		
		$('#yzm').blur(function(){
			
			var sj=$('#yzm').val();
			var p=$('#sj').val();
			if(p==''){
				$.messager.show({
					title:'提示',
					msg:'请输入手机号码',
					timeout:1000,
					showType:'slide'
				});
				return false;
			}
			$.ajax({
				'type':'post',
				'dateType':'json',
				'url':'${pageContext.request.contextPath}/student/checkYanZheng',
				'data':{
					'qyzm':sj,
				},
				'success':function(msg){
					
						if(msg.code==200){
							$('#yzmjg').css("background","url(../img/ok.png)");
							loginflag=msg.flag;
						}else{
							$('#yzmjg').css("background","url(../img/no.png)");
							loginflag=msg.flag;
						}
				}
			});
		});
		
		$('#btnyzm').click(function(){
			var sj=$('#sj').val();
			$.ajax({
				'type':'post',
				'dateType':'json',
				'url':'${pageContext.request.contextPath}/student/phoneyanzheng',
				'data':{
					'phonenum':sj,
				},
				'success':function(msg){
						if(msg.code==200){
						
						$.messager.show({
							title:'提示',
							msg:'验证已发送,请查看手机',
							timeout:1000,
							showType:'slide'
						});
					}
				}
			});
		});
		
		
		$('#lg').click(function(){
			
			var role=$(cc).combobox("getValue");
			var phone=$("input[name=phone]").val();
			var passwode=$("input[name=passwode]").val();
			//学生页面
			
		 	/* if(loginflag==0){
				
				$.messager.show({
					title:'提示',
					msg:'请输入正确的验证码',
					timeout:1000,
					showType:'slide'
				});
				return false;
			}   */
			if(role==1){
				
				$.ajax({
					'type':'post',
					'dateType':'json',
					'url':'${pageContext.request.contextPath}/student/mylogin',
					'data':{
						'loginNo':phone,
						'password':passwode,
					},
					'success':function(msg){
						if(msg.code==200){
							
							$.messager.show({
								title:'登陆成功',
								msg:'消息将在1秒后关闭。',
								timeout:1000,
								showType:'slide'
							});
							
							setTimeout(goMain(), 1000);
						}else{
							$.messager.show({
								title:'登陆失败',
								msg:'账号或密码错误。',
								timeout:8000,
								showType:'slide'
							});
						}
					},
				});
			}else{
				
				//管理员登陆
				$.ajax({
					'type':'post',
					'dateType':'json',
					'url':'${pageContext.request.contextPath}/admin/mylogin',
					'data':{
						'loginNo':phone,
						'password':passwode,
					},
					'success':function(msg){
						if(msg.code==200){
							
							$.messager.show({
								title:'登陆成功',
								msg:'消息将在1秒后关闭。',
								timeout:1000,
								showType:'slide'
							});
							setTimeout(goMain(), 1000);
						}else{
							$.messager.show({
								title:'登陆失败',
								msg:'账号或密码错误。',
								timeout:8000,
								showType:'slide'
							});
						}
					},
				});
				
			}
			
				
		});
				
			
			
			
		
	});
	
	function goMain(){
		window.location.href="${pageContext.request.contextPath}/tree/index.jsp";
	}
	
	//去注册
	$('#reg').click(function(){
		window.location.href="${pageContext.request.contextPath}/login/reg.jsp";
	});

</script>
</html>